/*
 * @Author: 谢陈洁
 * @Date: 2025-07-23 11:35:24
 * @LastEditors: 谢陈洁
 * @LastEditTime: 2025-07-23 22:36:00
 * @Description: file content
 */
import type { RouteRecordRaw } from "vue-router"
const preloadedModules = import.meta.glob('../views/**/*.vue') // 预加载所有组件

export const gernarateRoutes = (menuData: any[]) => {
  return menuData.map((item: any):RouteRecordRaw => {
    const componentPath = item.component.replace('@/views', '').replace('.vue', '')
    const route: RouteRecordRaw = {
      path: item.path,
      name: item.name,
      component: item.component==='layout'? () => import(`@/layouts/index.vue`): preloadedModules[`../views${componentPath}.vue`],
      meta: {
        title: item.title,
        icon: item.icon,
        hidden: item.status === 0, // 0:隐藏 1:正常
        dynamic: true,
      },
      children: item.children && gernarateRoutes(item.children)
    }
    return route
  })
}
